<!--  -->
<template>
  <div class="content">
    <van-popup v-model="sponShow" closeable position="bottom" round @close="sponClose" >
      <div class="sponsor-main">
        <h3>发起转赠</h3>
        <div class="member-id flex">
          <div class="label">受赠人ID</div>
          <input placeholder="请输入" v-model.trim="params.transfer_id"  placeholder-style="color:#AAAAB3;" @input="throttleFn" />
        </div>
        <div class="member-name" v-show="memberFlag">昵称：{{memberName}}</div>
        <div class="member-number flex-a-c flex-j-sb">
          <div class="label">转赠数量<span>（最多可转赠数量{{maxtotal}}）</span></div>
          <div>
            <van-stepper v-model="params.total" min="1" :max="maxtotal" integer />
          </div>
        </div>
        <div class="sponsor-confrim" @click="sponsorClick">确认转赠</div>
      </div>
    </van-popup>
  </div>
</template>
<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
name:'',
props: {
  sponShow: Boolean,
  maxtotal:Number,
  params:Object
},
//import引入的组件需要注入到对象中才能使用
components: {},
data() {
  return {
    memberFlag:false,
    memberName:{},
    memberId:'',
    timeoutId:''
  };
},
//监听属性 类似于data概念
computed: {},
//监控data中的数据变化
watch: {},
//方法集合
methods: {
  sponsorClick() {
    if(this.memberFlag && this.memberId) {
      this.$emit('sponsorConfrim','');
      this.$emit('update:sponShow',false);
    } else {
      this.$toast('请输入正确会员ID');
    }
  },
  sponClose() {
    
    this.$emit('update:sponShow', false);
  },
  throttleFn(event) {
      console.log(this.params.transfer_id);
      if (this.timeoutId) {
        clearTimeout(this.timeoutId);
      }
      console.log(event);
      this.timeoutId = setTimeout(() => {
        this.memberId = this.params.transfer_id;
          this.searchMember()
        // this.searchConpon(); //查询优惠劵
      }, 300);
    },
  //查询会员
  searchMember() {
    this.memberFlag = false;
    $http.post("plugin.collection-center.frontend.controllers.collection.member.search-member", {member_id: Number(this.memberId)})
      .then((response) => {
        if (response.result == 1) {
          console.log(response.data);
          let data = response.data;
          this.memberName = data.member?.nickname;
          if(this.memberName) {
            this.memberFlag = true;
          }
        }
        if (response.data.length <= 0) {
          this.memberFlag = false;
        }
    })
    .catch((err) => {
      console.log(err)
    });
  },
},
//生命周期 - 创建完成（可以访问当前this实例）
created() {
},
//生命周期 - 挂载完成（可以访问DOM元素）
mounted() {

},
beforeCreate() {}, //生命周期 - 创建之前
beforeMount() {}, //生命周期 - 挂载之前
beforeUpdate() {}, //生命周期 - 更新之前
updated() {}, //生命周期 - 更新之后
beforeDestroy() {}, //生命周期 - 销毁之前
destroyed() {}, //生命周期 - 销毁完成
activated() {
}, //如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style lang="scss" scoped>
/* @import url(); 引入公共css类 */
  .sponsor-main {
    padding:22px 0 25px 0;
    margin:0 12px;
    h3 {
      font-size: 16px;
      font-weight: bold;
      color: #00001C;
      line-height: 24px;
    }
    .member-id {
      padding:28px 0 16px 0;
      border-bottom: 1px solid #F0F0F1;
      position: relative;
      .label {
        font-size: 14px;
        color: #00001C;
        font-weight: normal;
        line-height: 24px;
        padding:0 24px 0 0;
      }
      input {
        border: none;
        outline: none;
        :focus {
          outline: none;
        }
        ::-webkit-input-placeholder {
          color:#AAAAB3;
        }
      }
    }
    .member-name {
      font-size: 13px;
      color: #F15353;
      line-height: 13px;
      padding:7px 0 0 80px;
      text-align: left;
    }
    .member-number {
      padding:37px 0 44px 0;
      .label {
        font-size: 14px;
        color: #00001C;
        line-height: 24px;
        span {
          font-size: 13px;
          font-weight: normal;
          color: #AAAAB3;
          line-height: 24px;
        }
      }
    }
    .sponsor-confrim {
      width: 100%;
      padding:13px 0;
      font-size: 15px;
      line-height: 15px;
      background-color: var(--themeBaseColor);
      font-weight: 400;
      color: #FFFFFF;
      border-radius: 21px 21px 21px 21px;
    }
  }
</style>